package com.gcxy.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author WangZhixian
 * @description
 * @date 2020/12/31
 */
@Slf4j
public class BeanUtil {

    public static <S, T> List<T> copyList(List<S> sourceList, Class<T> targetClass) {
        List<T> targetList = new ArrayList<>();
        try {
            for (S source : sourceList) {
                T targetInstance = targetClass.newInstance();
                BeanUtils.copyProperties(source, targetInstance);
                targetList.add(targetInstance);
            }
        } catch (Exception e) {

            return null;
        }
        return targetList;
    }
}
